<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    String ctx = request.getContextPath();
    request.setAttribute("ctx", ctx);
%>
<html>
<head>
    <title>Title</title>
    <script src="js/jquery-1.9.1.min.js"></script>
    <script src="js/fileupload.js"></script>
    <script src="My97DatePicker/WdatePicker.js"></script>
    <link rel="stylesheet" href="css/img.css">
    <script>
        function fenye(cpage) {
            $("[name='cpage']").val(cpage);
            $("form").submit();
        }
        function toadd() {
            location="toadd.do";
        }
        function toupd(aid) {
            location="toupd.do?aid="+aid;
        }
        function del(aid) {
            $.ajax({
                       url:"del.do",
                       type:"post",
                       data:{"aid":aid},
                       dataType:"json",
                       success:function(obj) {
                           if (obj>0){
                               alert("删除成功");
                               location="list.do";
                           }
                       }
                  })
        }
    </script>
</head>
<body>
<form action="list.do" method="post">
    <input type="hidden" name="cpage">
    标题:<input type="text" name="mohu1" value="${map.mohu1}">
    内容:<input type="text" name="mohu2" value="${map.mohu2}">
    <input type="submit" value="查询">
</form>
<table border="1">
    <tr>
        <td>编号</td>
        <td>标签</td>
        <td>标题</td>
        <td>图片</td>
        <td>内容</td>
        <td>创建时间</td>
        <td>
            <input type="button" value="添加" onclick="toadd()">
        </td>
    </tr>
    <c:forEach items="${pageInfo.list}" var="a">
        <tr>
            <td>${a.aid}</td>
            <td>${a.names}</td>
            <td>${a.title}</td>
            <td>
                <img src="${a.img}" alt="无法展示" width="80px">
            </td>
            <td>${a.content}</td>
            <td>${a.createtime}</td>
            <td>
                <input type="button" value="删除" onclick="del(${a.aid})">
                <input type="button" value="编辑" onclick="toupd(${a.aid})">
            </td>
        </tr>
    </c:forEach>
    <tr>
        <td colspan="11">
            <input type="button" value="首页" onclick="fenye(1)">
            <input type="button" value="上一页" onclick="fenye(${pageInfo.isFirstPage?1:pageInfo.prePage})">
            <input type="button" value="下一页" onclick="fenye(${pageInfo.isLastPage?pageInfo.pages:pageInfo.nextPage})">
            <input type="button" value="尾页" onclick="fenye(${pageInfo.pages})">
        </td>
    </tr>
</table>
</body>
</html>
